/*! \file udk.h
This file describes all the APIs of the UDK platform.
\copyright Copyright(c) 2015 by ZKTeco Co., Ltd. All Rights Reserved.*/

#ifndef UDK_H
#define UDK_H

#include "udk_types.h"


__BEGIN_DECLS


//typedef void (UDK_API* PCBUDKDownload)(int type, int length);


/* ============================================================================
 * UDK Protocol Declaration
 * ============================================================================
 */
/** Auto detect protocol. */
#define UDK_PROT_DEFAULT 0
/** PullSDK protocol. */
#define UDK_PROT_PULL 1
/** StdSDK protocol. */
#define UDK_PROT_STANDALONE 2

/** LockState with sense. */
#define UDK_LOCK_STATE_WITHOUT_SENSE 0
/** LockState ON. */
#define UDK_LOCK_STATE_LOCK_ON 1
/** LockState OFF. */
#define UDK_LOCK_STATE_LOCK_OFF 2
/* ============================================================================
 * Function Declaration
 * ============================================================================
 */
/**
 * \brief Connect target devices through UDK
 *
 * \details This function will connect target device by specified protocol and connect parameters
 * \param prot [inout] Protocol used to connect target device <br>
 *		#UDK_PROT_DEFAULT means autodetect and target device protocol is assigned in prot <br>
 *		#UDK_PROT_PULL use Pull Protocol <br>
 *		#UDK_PROT_STANDALONE use Standalone Protocol <br>
 * \param parameters [in] connect paramters string <br>
 *		Some examples:"protocol=RS232,port=COM1,baudrate=115200bps,timeout=1200000,passwd=0" <br>
 *			"protocol=RS485,port=COM2,baudrate=115200bps,deviceid=1,timeout=1200000,passwd=0" <br>
 * 			"protocol=UDP,ipaddress=192.168.1.201,port=4370,timeout=1200000,passwd=0" <br>
 *			"protocol=HTTP,ipaddress=192.168.1.201,port=80,name=12345,passwd=12345" <br>
 *			"protocol=HTTPS,ipaddress=192.168.1.201,port=80,name=12345,passwd=12345" <br>
 *
 * \return Connect Handle if connect successful,otherwise return NULL
 *
 */
UDK_HANDLE  
	UdkConnect(int* prot,const char *parameters);
/**
 * \brief Disconnect target devices 
 *
 * \details This function will disconnect target device by valid Handle
 * \param h [in] Handle returned through UdkConnect
 *
 */
void 
	UdkDisconnect(UDK_HANDLE h);

/**
 * \brief Get Last internal error code 
 *
 * \details This function will get last error code
 * \param h [in] Handle returned through UdkConnect,if connect failed, pass NULL to h.
 * \return
 *	-14 	means wrong password  <br>
 *	-203	means init socket fail <br>
 *	-307	means create socket timeout <br>
 */
int
	UdkGetLastError(UDK_HANDLE h);
	
/**
 * \brief Search Devices
 *
 * \details This function will search devices existed in connect network <br>
 * 		Generally this is used for TCP/IP based network
 * \param CommType [in] CommType <br>
 *		- "UDP"
 *		- "ETH"
 *		- "RS232"
 *		- "RS485"
 * \param Address  [in] Broadcast address,only used when CommType is "UDP" "ETH"<br>
 *		e.g 192.168.1.255 for subnet 192.168.1.0 broadcast <br>
 *		    255.255.255.255 for all subnet broadcast
 * \param Buffer [in] Buffer used to store device addresses searched. "TCP" or "UDP"
 * \param BufferLength [in] Buffer Size,and return buffer length received.
 *
 *
 * \return Control door state success or fail <br>
 *	>=0 means operation successful otherwise failed. <br>
 */
int 
	UdkSearchDevices(char *CommType,char *Address, char *Buffer,int* BufferLength);

/**
 * \brief Control Door State
 *
 * \details This function will open target devce connected door lock
 * \param h [in] Handle returned through UdkConnect
 *
 * \return Lock count >=0 if operation successful
 *	<0 means operation failed.
 */
int 
	UdkGetLockCount(UDK_HANDLE h);

/**
 * \brief Control Lock State
 *
 * \details This function will open target devce connected lock
 * \param h [in] Handle returned through UdkConnect
 * \param lock_no [in] lock number to open,start from 1
 * \param opentime [in] open time,<br>
 *		- 0 door always locked
 *		- 1~60 open request time (unit:second)
 *		- 255 door always open
 *
 * \return Control door state success or fail <br>
 *	>=0 means operation successful otherwise failed.
 */
int 
	UdkSetLockState(UDK_HANDLE h,int lock_no,int opentime);
/**
 * \brief Get lock State
 *
 * \details This function will fetch door lock sense state
 * \param h [in] Handle returned through UdkConnect
 * \param lock_no [in] lock number to open,start from 1 <br>
 *		0 means all locks state
 *
 * \return Current lock state fail <br>
 *	This lock state is combined value which means higher bytes is high number lock state<br>
 *      each byte has 3 states <br>
 *	- #UDK_LOCK_STATE_WITHOUT_SENSE-> no sense installed
 *	- #UDK_LOCK_STATE_LOCK_ON->lock is on
 *	- #UDK_LOCK_STATE_LOCK_OFF->lock is off <br>
 *	e.g 0x01000000 means lock no 4 state is on <br>
 *	e.g 0x00000002 means lock no 1 state is off <br>
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
 */
int 
	UdkGetLockState(UDK_HANDLE h,int lock_no);

/**
 * \brief Get communication password
 *
 * \details This function will get the password of communication
 * \param h [in] Handle returned through UdkConnect
 * \param Buffer [in] Buffer used to store communication password
 * \param BufferLength [in] Buffer Size,and return buffer length received.
 * \return 
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
*/
int 
	UdkGetComPwd(UDK_HANDLE h, char *buffer, int *BufferLength);

/**
 * \brief Mobile attendance
 *
 * \details This function will do something about mobile attendance
 * \param h [in] Handle returned through UdkConnect
 * \param operate [in] 1 means query token <br>
 *			2 means set token  <br>
 *			3 means wifi check in  <br>
 *			4 means pull personal report  <br>
 *			5 means pull company report <br>
 *			6 means pull att record
 * \param premeters provide hardware id when operate=1(hwid=xx) <br>
 *					provide hardware id,pin,user password by md5-16(hwid=xxx,pin=xxx,pwd=xx) when operate=2 or operate=3  <br>
 *					provide hardware id,pin,user password by md5-16,start time, end time and
 *				table header(hwid=xxx,pin=xxx,pwd=xx,start=x,end=x,th=x|x|,type=0/1;0 means exception report,1 means full report) when operate=4 <br>
 *					provide hardware id,pin,user password by md5-16,start time, end time and
 *				table header(hwid=xxx,pin=xxx,pwd=xx,start=x,end=x,th=x|x|,type=0/1;0 means full report for admin,1 means summary report for personal) when operate=5
 *					provide hardware id,pin,user password by md5-16,start time,end time and <br>
 *				reccord type (hwid=xxx,pin=xxx,pwd=xx,start=x,end=x,type=0/1;0 means personal record) when operate=6
 * \param Buffer [in] Buffer used to store return data<br>for example <br>
 *					Buffer:"pin=x,name=x,right=x" when operate=1/2 and function succ  <br>
 *					Buffer:"time=(time stamp)" when operate=3 and function succ<br>
 *					Buffer:"summary buffer[\n\t\r]detail buffer" when operate=3/4 and function succ, see report.txt for detail. <br>
 *					Buffer:"{"pin":"xx","name":"xx","startTime":"20151201","endTime"="20151215","data":[{"day":"20151201","records":"7:42,18:09"}]}" 
 *				when operate=6 and function succ
 * \param BufferLength [in] Buffer Size,and return buffer length received.
 * \return 
 *	- 1 	operate successful
 *  - 0 	no data
 *	- -2	io error
 *	- -3	invalid data(error size)
 *	- -100	operate not support
 *	- -2001 command was not support.
 *	- -2008 pin was not exist
 *	- -2009 user password was null
 *	- -2010 wrong password
 *	- -2011	the user had already binded with this phone
 *	- -2012 the user had already binded but not this phone
 *	- -2013 the phone was not binded
 *	- -2014 the user was not administrator
 *  - -2015 calc report fail
 *	- -other fail
*/
int 
	UdkMobileAtt(UDK_HANDLE h, int operate, char *premeters, char *Buffer,int* BufferLength);

/**
 * \brief Get the device parameter
 *
 * \detail This function will get the parameter of device
 * \param h [in] Handle returned through UdkConnect
 * \param Buffer [in] Buffer used to store return data,for example<br>
 *					"WirelessAPSSID=x60"
 * \param Bufferlen [in] Buffer Size.
 * \param Item some example<br>
 *				"DeviceID":get the device id,will be used for keepalive  <br>
 *				"WirelessAPSSID":get the Wireless AP SSID  <br>
 *				"WirelessAPPasswd": get the Wireless AP Password
 * \return 
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
*/
int 
	UdkGetDeviceParam(UDK_HANDLE h, char *Buffer, int Bufferlen, char *Item);

/**
 * \brief set the device parameter
 *
 * \detail This function will set the parameter of device
 * \param h [in] Handle returned through UdkConnect
 * \param ItemandValues some example<br>
 *				"WirelessAPSSID=x60":set the Wireless AP SSID name as "x60"  <br>
 *				"WirelessAPPasswd=12345678": set the Wireless AP password  <br>
 * \return 
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
*/

int 
	UdkSetDeviceParam(UDK_HANDLE h, char *ItemandValues);
/**
 * \brief set the callback function of downprocess
 *
 * \detail set the callback function of downprocess
 * \param h [in] Handle returned through UdkConnect
 * \param pCallBackFun [in] the callback function pointer, the function definition: <br>
 *			void UDK_API CBDownloadProcess(int type, int size);	<br>
 *			type=0 means totalsize;type=1 means size has been read <br>
 * \return 
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
*/
int 
	UdkSetDownloadProcessCallBack(UDK_HANDLE h, void *pCallBackFun);

/**
 * \brief reset device extend function
 *
 * \detail support reset sub module
 * \param h [in] Handle returned through UdkConnect
 * \param parameters [in] <br>
 *			for example "module=wifi"<br>
 *			parameter=null/"" means reset device <br>
 *			support reset multiple modules(module=x1,module=x2,...)
 * \return 
 *	- >=0 operate successful
 *	- <0  operate failed,error is returned.
*/
int
	UdkResetDeviceExt(UDK_HANDLE h, char *parameters);


__END_DECLS 

#endif //UDK_H
